var serverData = {};
serverData.key ='';
var	serverTable;
//快速录入
jQuery('.addfastBtn').on("click",function(){
	var url=window.rootPath+'/ui/myMoney/addfast';
	window.location = url;
});
//查询
jQuery('.searchBtn').on("click",function(){
	serverData.key = jQuery("#keyword").val();
	serverTable.draw();
});
//查询
jQuery('.submitBtn').on("click",function(){
	jQuery("#keyword").val('');
	serverData.key = jQuery("#keyword").val();
	serverTable.draw();
});
//新增
jQuery('.addBtn').on("click",function(){
	var url=window.rootPath+'/ui/myMoney/addInterface';
	window.location = url;
});
//删除
jQuery('.deleteBtn').on("click",function(){
	var selects=getSelect("#dataTable",1);
	   if(selects.length>1){
		   $.springLemonDialog({
		         content: '只能删除一条记录',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		             $(this).closeDialog(modal);
		         }
		   }); 
	   }
	   else if(selects.length==0){
		   $.springLemonDialog({
		         content: '请选择要删除的记录',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		             $(this).closeDialog(modal);
		         }
		   }); 
	   }
	   var id = selects[0].id
	   var url = window.rootPath + "/ui/myMoney/deleteMyMoney?id="+id;
	  
	   //serverData.id = id;
	   jQuery.ajax({
	        type: 'post',
	        url:  encodeURI(url),
	        data: JSON.stringify(),
	        dataType: 'json',
	        contentType: 'application/json;charset=utf-8',
	        success: function (data) {
	        	//serverData.myMoneyId = jQuery("#id").val();
	        	serverTable.draw();
	        }
		
	    });
});
//编辑
jQuery('.updateBtn').on("click",function(){
	var selects=getSelect("#dataTable",1);
	   if(selects.length>1){
		   $.springLemonDialog({
		         content: '只能删除一条记录',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		             $(this).closeDialog(modal);
		         }
		   }); 
	   }
	   else if(selects.length==0){
		   $.springLemonDialog({
		         content: '请选择要删除的记录',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		             $(this).closeDialog(modal);
		         }
		   }); 
	   }else{
		   var id = selects[0].id
		   window.location = window.rootPath + "/ui/myMoney/updateMyMoney?id="+id; 
	   }
});
//查看
jQuery('.viewBtn').on("click",function(){
	var selects=getSelect("#dataTable",1);
	   if(selects.length>1){
		   $.springLemonDialog({
		         content: '只能删除一条记录',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		             $(this).closeDialog(modal);
		         }
		   }); 
	   }
	   else if(selects.length==0){
		   $.springLemonDialog({
		         content: '请选择要删除的记录',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		             $(this).closeDialog(modal);
		         }
		   }); 
	   }else{
		   var id = selects[0].id
		   window.location = window.rootPath + "/ui/myMoney/viewMyMoney?id="+id; 
	   }
});
jQuery(document).ready(function () {

	   serverTable=  jQuery('#dataTable').DataTable({
        "serverSide": true,
        "ordering": false,
        "ajax": {
            "dataType": "json",
            "type": "get",
            "cache": false,
            "url": window.rootPath+'/ui/myMoney/selectMyMoney',
            "data": function (d) {
                return $.extend({}, d, serverData);
            }
        },
        columns: [{
			        	data: null,
			            defaultContent: ""
			        },
			        {
			        	data:null,
					    render: function(data, type, full, meta){
					    	var operate ='<input type="checkbox" class="checkchild">';
					    	var id=data.id;
					    	return operate;
							}
		            },
                  	{
		                data: 'applyArea'
		                
		            },
		            {
		                data: 'useContent'
		            },
		            {
		                data: 'applyUserName'
		            },
		            {
		            	data: 'applyDate',
		            	render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		            	data: 'outStartDate',
		            	render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		            	data: 'backDate',
		            	render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		                data: 'outDays'
		            },
		            {
		                data: 'memo'
		            }
		          ],
        "drawCallback": function ( oSettings ) {             
            var k = 0;
            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

            for ( var i=oSettings._iDisplayStart, iLen=total ; i<iLen ; i++ )
            {
                $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[k] ].nTr ).text( i+1 );
                k++;
            }
                return;
        }
    });

});